
	_status = $("div.jgdb > p.msg").html();
	_status=_status.indexOf('英雄需要達到5級')>0?false:true;
function gdpf_handler(){
	if(!_status){
		log('您的英雄尚未達到使用酒館的等級,請稍候再試');
		clickLink('/mindex');
		return;
	}else{
		
		//check whether you have complete the gamble today
		var msg = $x("//div[@class='jgdb']/p[@class='msg']")[0];
		if(msg != null && msg.innerHTML == '您今天不能再玩了。'){
		  log("對不起,今天的賭博已經結束.掉轉到首頁...");
		  //GM_setValue("ds_gambleOver_"+window.location.host,(new Date()).toLocaleDateString());
		  GM_safeVariables["ds_gambleOver_"+window.location.host] = (new Date()).toLocaleDateString();
		  clickLink("/mindex");
		  return;
		}

		log('按配置进行自动赌博..祝你好運氣!');
		var imgs = document.getElementsByTagName('img');
			var img = null;
			for(var i=0;i<imgs.length;i++){
			  if(imgs[i].getAttribute("title") == '銀' && imgs[i].getAttribute("src") == "/sys/images/z/z_yin.gif"){
				img = imgs[i];
				break;
			  }
			}
			if(img == null){
			  log("無法正確獲取您當前的金幣信息,掉轉到首頁...");
			  //GM_setValue("ds_gambleOver_"+window.location.host,(new Date()).toLocaleDateString());
			  GM_safeVariables["ds_gambleOver_"+window.location.host] = (new Date()).toLocaleDateString();
			  clickLink("/mindex");
			  return;
			}
			var coinCount = parseInt(img.parentNode.childNodes[0].nodeValue.toString());
			//str = str.substring(0,str.indexOf("<br/>"));
			if(coinCount > 120){
			  log("好了,財主,我們開始賭博把!");
			}else{
			  log("似乎你有點窮人的樣子噢,還是等金幣大於120的時候再來賭博把,正在掉轉到首頁...");
			  //GM_setValue("ds_gambleOver_"+window.location.host,(new Date()).toLocaleDateString());
			  GM_safeVariables["ds_gambleOver_"+window.location.host] = (new Date()).toLocaleDateString();
			  clickLink("/mindex");
			  return;
			}
			
			var random = Math.random()*10;
			var id = "";
			if(random>=0&&random<=1){
			  id = "b3";
			}else if(random>1&&random<=5.5){
			  id = "b1";
			}else{
			  id = "b2";
			}
			document.getElementById(id).checked = true;
			log("已經下注,屏住呼吸,等待開牌...");
			//clickLink("");
			var submitForm = $x("//div[@class='jgdb']/form")[0];
			if(submitForm != null){
			  var randomTime = Math.random()*10000;
			  randomTime = randomTime<2000?2000:randomTime;
			  window.setTimeout(function(){
				submitForm.submit();
			  },randomTime);
			}else{
			  log("找不到開牌按鈕,系統錯誤...掉轉到首頁...");
			  //GM_setValue("ds_gambleOver_"+window.location.host,(new Date()).toLocaleDateString());
			  GM_safeVariables["ds_gambleOver_"+window.location.host] = (new Date()).toLocaleDateString();
			  clickLink("/mindex");
			  return;
			}
		  }//elseif
	}//function end

function gdpf_handler_configMode(){
	if(_status){
		log('進入賭博頁面，配置自動賭博設置');
		$('.jgdb2').after('<div style="border:1px solid #CCCCCC;padding:10px;float:left;margin-top:5px;color:#999999"><p><input type="checkbox" id="ds_cfg_chkAutoGamble"/><label for="ds_cfg_chkAutoGamble">啟用自動賭博(利用空閒時間完成100次系統允許的賭博)</label></p></div>');
		/*$('.jgdb2').after(['<div style="border:1px solid #CCCCCC;padding:10px;float:left;margin-top:5px;color:#999999">',
				'<p>',
					'<span>自動猜結果:<input type="radio">豹子<input type="radio">小<input type="radio">大<input type="radio">隨機</span>',
				'</p>',
				'</div>'
				].join(''));*///未開發完成
		$("#ds_cfg_chkAutoGamble").get(0).checked = CONFIG.auto_gamble;
		$("#ds_cfg_chkAutoGamble").click(function(){
			CONFIG.auto_gamble = $("#ds_cfg_chkAutoGamble").get(0).checked;
		});
	}else{
		log('您的英雄尚未達到使用酒館的等級,請稍候再試,您可以手動返回首頁');
		return;
	}
	
}